home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / os2 / elvis172.zip / move4.c < prev    next >
C/C++ Source or Header  |  1993-01-06  |  4KB  |  221 lines

  1. /* move4.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* This file contains movement functions which are screen-relative */
  12.  
  13. #include "config.h"
  14. #include "vi.h"
  15.  
  16. /* This moves the cursor to a particular row on the screen */
  17. /*ARGSUSED*/
  18. MARK m_row(m, cnt, key)
  19.     MARK    m;    /* the cursor position */
  20.     long    cnt;    /* the row we'll move to */
  21.     int    key;    /* the keystroke of this move - H/L/M */
  22. {
  23.     DEFAULT(1);
  24.  
  25.     /* calculate destination line based on key */
  26.     cnt--;
  27.     switch (key)
  28.     {
  29.       case 'H':
  30.         cnt = topline + cnt;
  31.         break;
  32.  
  33.       case 'M':
  34.         cnt = topline + (LINES - 1) / 2;
  35.         break;
  36.  
  37.       case 'L':
  38.         cnt = botline - cnt;
  39.         break;
  40.     }
  41.  
  42.     /* return the mark of the destination line */
  43.     return MARK_AT_LINE(cnt);
  44. }
  45.  
  46.  
  47. /* This function repositions the current line to show on a given row */
  48. MARK m_z(m, cnt, key)
  49.     MARK    m;    /* the cursor */
  50.     long    cnt;    /* the line number we're repositioning */
  51.     int    key;    /* key struck after the z */
  52. {
  53.     long    newtop;
  54.     int    i;
  55.  
  56.     /* Which line are we talking about? */
  57.     if (cnt < 0 || cnt > nlines)
  58.     {
  59.         return MARK_UNSET;
  60.     }
  61.     if (cnt)
  62.     {
  63.         m = MARK_AT_LINE(cnt);
  64.         newtop = cnt;
  65.     }
  66.     else
  67.     {
  68.         newtop = markline(m);
  69.     }
  70.  
  71.     /* allow a "window size" number to be entered */
  72.     for (i = 0; key >= '0' && key <= '9'; key = getkey(0))
  73.     {
  74.         i = i * 10 + key - '0';
  75.     }
  76. #ifndef CRUNCH
  77.     if (i > 0 && i <= LINES - 1)
  78.     {
  79.         *o_window = i;
  80.         wset = TRUE;
  81.     }
  82. #else
  83.     /* the number is ignored if -DCRUNCH */
  84. #endif
  85.  
  86.     /* figure out which line will have to be at the top of the screen */
  87.     switch (key)
  88.     {
  89.       case '\n':
  90. #if OSK
  91.       case '\l':
  92. #else
  93.       case '\r':
  94. #endif
  95.       case '+':
  96.         break;
  97.  
  98.       case '.':
  99.       case 'z':
  100.         newtop -= LINES / 2;
  101.         break;
  102.  
  103.       case '-':
  104.         newtop -= LINES - 1;
  105.         break;
  106.  
  107.       default:
  108.         return MARK_UNSET;
  109.     }
  110.  
  111.     /* make the new topline take effect */
  112.     redraw(MARK_UNSET, FALSE);
  113.     if (newtop >= 1)
  114.     {
  115.         topline = newtop;
  116.     }
  117.     else
  118.     {
  119.         topline = 1L;
  120.     }
  121.     redrawrange(0L, INFINITY, INFINITY);
  122.  
  123.     /* The cursor doesn't move */
  124.     return m;
  125. }
  126.  
  127.  
  128. /* This function scrolls the screen.  It does this by calling redraw() with
  129.  * an off-screen line as the argument.  It will move the cursor if necessary
  130.  * so that the cursor is on the new screen.
  131.  */
  132. /*ARGSUSED*/
  133. MARK m_scroll(m, cnt, key)
  134.     MARK    m;    /* the cursor position */
  135.     long    cnt;    /* for some keys: the number of lines to scroll */
  136.     int    key;    /* keystroke that causes this movement */
  137. {
  138.     MARK    tmp;    /* a temporary mark, used as arg to redraw() */
  139. #ifndef CRUNCH
  140.     int    savenearscroll;
  141.  
  142.     savenearscroll = *o_nearscroll;
  143.     *o_nearscroll = LINES;
  144. #endif
  145.  
  146.     /* adjust cnt, and maybe *o_scroll, depending of key */
  147.     switch (key)
  148.     {
  149.       case ctrl('F'):
  150.       case ctrl('B'):
  151.         DEFAULT(1);
  152.         redrawrange(0L, INFINITY, INFINITY); /* force complete redraw */
  153.         cnt = cnt * (LINES - 1) - 2; /* keeps two old lines on screen */
  154.         break;
  155.  
  156.       case ctrl('E'):
  157.       case ctrl('Y'):
  158.         DEFAULT(1);
  159.         break;
  160.  
  161.       case ctrl('U'):
  162.       case ctrl('D'):
  163.         if (cnt == 0) /* default */
  164.         {
  165.             cnt = *o_scroll;
  166.         }
  167.         else
  168.         {
  169.             if (cnt > LINES - 1)
  170.             {
  171.                 cnt = LINES - 1;
  172.             }
  173.             *o_scroll = cnt;
  174.         }
  175.         break;
  176.     }
  177.  
  178.     /* scroll up or down, depending on key */
  179.     switch (key)
  180.     {
  181.       case ctrl('B'):
  182.       case ctrl('Y'):
  183.       case ctrl('U'):
  184.         cnt = topline - cnt;
  185.         if (cnt < 1L)
  186.         {
  187.             cnt = 1L;
  188.             m = MARK_FIRST;
  189.         }
  190.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  191.         redraw(tmp, FALSE);
  192.         if (markline(m) > botline)
  193.         {
  194.             m = MARK_AT_LINE(botline);
  195.         }
  196.         break;
  197.  
  198.       case ctrl('F'):
  199.       case ctrl('E'):
  200.       case ctrl('D'):
  201.         cnt = botline + cnt;
  202.         if (cnt > nlines)
  203.         {
  204.             cnt = nlines;
  205.             m = MARK_LAST;
  206.         }
  207.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  208.         redraw(tmp, FALSE);
  209.         if (markline(m) < topline)
  210.         {
  211.             m = MARK_AT_LINE(topline);
  212.         }
  213.         break;
  214.     }
  215.  
  216. #ifndef CRUNCH
  217.     *o_nearscroll = savenearscroll;
  218. #endif
  219.     return m;
  220. }
  221.